<% @main_header = "#{link_to('Ptrack:', '/')} #{@project.name if @project}: Documents" %>

<div id="info" class='column span-8' style="width: 100%;">
  <div style="width: 60%; float: left;">
    <h3><%= link_to "Create New Document", :action=> :new %></h3>
  </div>
</div>
<div style="float: left; width: 100%;">
  <fieldset>

    <% unless @project %>
      <legend>All Documents</legend>
    <% else %>
      <legend>Project Documents</legend>
    <% end %>

    <table>
      <tr>
        <td style="font-weight: bold;">
          Title
        </td>

        <% unless @project %>
          <td style="font-weight: bold;">
            Project
          </td>
        <% end %>

        <td style="font-weight: bold;">
          File Type
        </td>
        <td style="font-weight: bold;">
          File Name
        </td>

        <td></td>
        <td></td>
      </tr>
      <tr>
        <td colspan="7">
          <hr>
        </td>
      </tr>
      <% for document in @documents %>
        <tr>
          <td><%=h document.name %></td>
          
          <% unless @project %>
            <td><%=document.project.nil? ? "Project Not Specified" : h(document.project.name) %></td>
          <% end %>

          <td><%=document.content_type.nil? ? "-" : h(document.content_type) %></td>
          <td><%=document.filename.nil? ? "-" : h(document.filename) %></td>

          <td><%= link_to "Download", :action => "download", :id => document%></td>
          <td><%= link_to("Delete", {:action => "destroy", :id => document}, :post => true, :confirm => "Are you sure want to delete document #{document.name}?")%></td>
        </tr>

      <% end %>
    </table>
  </fieldset>
</div>